module.exports = function($scope, $stateParams, $state, code, delsignup,
	outstate, infolist, cancleGroup, $modalInstance, userinfo){

	$scope.outstate = outstate;

	var name;

	userinfo().then(function(res) {
		name = res.name;
    });

	$scope.load = function(){
		infolist.get({'code' : code}, function(res){
			if(res.errcode === 0) {
				$scope.objs = res.data;
				$scope.zhengjiars = 0;
				$scope.butiers = 0;
				$scope.all_price = 0;

				if(res.data.length != 0) {
					angular.forEach(res.data, function(item){
						if(item.usedsubsidy != '0'){
							$scope.butiers ++;
						} else {
							$scope.zhengjiars ++;
						}
						$scope.all_price += parseInt(item.pay_price);
					});
				}
			} else {
				alert(res.errmsg);
			}
		});
	}
	$scope.load();

	$scope.back = function(id){
		var list = [];
		var list_map = {
			'id' : id,
			'name' : name
		};
        list.push(list_map);
	    cancleGroup.save({'cancleList' : list}, function(res){

	        if(res.errcode === 0)
	        {
	            alert("退订成功");
	            $scope.load();
	        }
	        else
	        {
	            alert(res.errmsg);
	        }

	    });
	}

	$scope.cancel = function () {
		$modalInstance.close();
	};

	$scope.signup = function(){
		$state.go('app.signupsellinggroup', {'code' : code});
	};

	$scope.del = function(id){
		var map = {
			'cancleList': [{'id': id}]
		};
	    delsignup.save(map, function(res){
	        if(res.errcode === 0){
	            alert("删除成功");
	            $scope.load();
	        } else {
	            alert(res.errmsg);
	        }
	    });
	}
	
};
